import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import Layout from '@/layout'

export const routes = [
  {
    path: '/home',
    component: Layout,
    children: [{
      path: '',
      component: () => import('@/views/Home/index'),
      meta: { title: '统计数据', icon: 'el-icon-pie-chart' }
    }]
  },
  {
    path: '/worker',
    component: Layout,
    children: [
      {
        path: '',
        component: () => import('@/views/People/index'),
        meta: { title: '负责人', icon: 'el-icon-user' }
    }]
  },
  {
    path: '/addmaintenance',
    component: Layout,
    children: [{
      path: '',
      component: () => import('@/views/MaintenanceApply'),
      meta: { title: '维修申请', icon: 'el-icon-setting' }
    }]
  },
  {
    path: '/operation',
    component: Layout,
    children: [{
      path: '',
      component: () => import('@/views/Operation'),
      meta: { title: '运维历史', icon: 'el-icon-tickets' }
    }]
  },  
  {
    path: '/pipe',
    component: Layout,
    children: [{
      path: '',
      component: () => import('@/views/Pipe/index'),
      meta: { title: '添加管道', icon: 'el-icon-circle-plus-outline' }
    }]
  },
  {
    path: '/login',
    component: () => import('@/views/Login/index'),
    hidden: true
  },
  {
    path: '/maintenanceapply',
    component: () => import('@/views/MaintenanceApply/add-maintenance-apply'),
    hidden: true
  },
  {
    path: '/addworker',
    component: () => import('@/views/People/AddWorker'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/home'
  },
  {
    path: '/bigscreen',
  },

  {
    path: '/:pathMatch(.*)',
    component: () => import('@/views/404'),
    hidden: true
  }

]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  mode: 'history',
  scrollBehavior: () => ({ y: 0 }),
  routes: routes
})

const router = createRouter()

// 重置路由方法
export function resetRouter() {
  // 得到一个全新的router实例对象
  const newRouter = createRouter()
  // 使用新的路由记录覆盖掉旧的路由记录
  router.matcher = newRouter.matcher
}

export default router
